TARGET		= hs

CC		= avr-gcc
OBJ2HEX		= avr-objcopy
MCU		= atmega8

CFLAGS		= -g -Os -mcall-prologues -mmcu=$(MCU) -Wall -Wstrict-prototypes -Wa,-ahlms=$(TARGET).lst -DF_CPU=8000000
#ASFLAGS	= -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS		= -Wl,-Map=$(TARGET).map,--cref -mmcu=$(MCU) -lm -lprintf_min

# Programmer. Ik gebruik avrdude icm crips programmer
PROGRAMMER	= avrdude
PRG_OPTIONS	= -c stk500v2 -P /dev/tty.usbserial-A7005tiJ -p m8 -v

OBJS		= mediatek.o led.o usart.o hs.o



# Create all target
all:	$(TARGET).hex

#
# Compile *.c -> *.o
hs.o:	hs.c
	$(CC) $(CFLAGS) -I. -c $<

mediatek.o:	mediatek.c mediatek.h
	$(CC) $(CFLAGS) -I. -c $<

usart.o:	usart.c usart.h
	$(CC) $(CFLAGS) -I. -c $<

led.o:	led.c led.h
	$(CC) $(CFLAGS) -I. -c $<
#		
# Linking all *.o -> *.elf
$(TARGET).elf	:	$(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) -o $(TARGET).elf

#
# Create intel hex for download
$(TARGET).hex	:	$(TARGET).elf
	$(OBJ2HEX) -O ihex $(TARGET).elf $(TARGET).hex
		
#
# install
install		:
	$(PROGRAMMER) $(PRG_OPTIONS) -U flash:w:$(TARGET).hex

#
# setconfig
setconfig	:
	$(PROGRAMMER) $(PRG_OPTIONS) -U lfuse:w:0xde:m -U hfuse:w:0xd9:m


#
# Production 
#
# Set resonator 8MHz
production	:
	$(PROGRAMMER) $(PRG_OPTIONS) -U lfuse:w:0xde:m -U hfuse:w:0xd9:m
	$(PROGRAMMER) $(PRG_OPTIONS) -U flash:w:production-07OKT11.hex
	
#
# clean
clean		:
		rm -f $(TARGET).hex *.o *.obj *.lst *.map *.elf
